<%@ page language="java" session="true" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="../common/framework/header.jsp" />
<link href="${pageContext.request.contextPath}/static/plugin/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<%-- <link href="${pageContext.request.contextPath}/static/css/testCase/sitecss.css" rel="stylesheet"> --%>
<link href="${pageContext.request.contextPath}/static/css/testCase/corecss.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/static/css/zTreeStyle/zTreeStyle.css" rel="stylesheet">
<style type="text/css">
	.panel-body {
		padding-bottom:0px;
	}
	.tree_menu:hover {
		background-color: #D4E5F5;
	}
	.tree_menu {
		padding: 8px
	}
	.showAll_open {
	background-color: #D4E5F5;
	
	}

	select.form-control {
	    height: 32px;
	    padding: 4px 6px;
	    width: 115px!important;
	}
	.testCase_right_title {
		padding:0;
	}
	.testCase_right_title>h4 {
		display:inline;
	}
	.testCase_right_title>a {
		margin-top: 10px;color:#fff;
	}
	.tdcolor {
		background-color: #eee
	}
	#gridTableDiv th {
   		background: #ddd;
	}
	#testCase_grid {
		display:none;
		margin-top: 10px;
	}
	#testCase_grid>a {
		color:#000;
	}
	#testCase_grid>a:hover {
		color:#007acc;
		text-decoration: none;
	}
	.tdcolor {
		background: #f5f5f5;
	}
	.coodo-grid {
    table-layout: fixed;
    margin-bottom: 0;
    margin-left: 0;
}
.bs-bars {
    padding-right: 100px;
}
.fixed-table-pagination .page-list {
    display: none;
}
/* 	.bs-bars{padding:0;} */
A:hover {
    color: #26a0f5;
    text-decoration: none;
}
#testCase_list .bs-bars {
    padding-right: 41px;
}
</style>
	<div id="container"
		class="effect aside-float aside-bright mainnav-lg navbar-fixed mainnav-fixed aside-fixed">

		<jsp:include page="../common/framework/topper.jsp" />
		<div class="boxed">
			<%--=======================  页面主体内容  ============================--%>
			<div id="content-container">
				<div class="wrappers">
					<%--=========================  页面标题  ==========================--%>
					<div id="page-title">
						<p class="page-header text-overflow table-header">
							测试用例&nbsp;&nbsp;<small>编辑测试用例，并同步至JIRA，提供导入和导出功能。详细说明请参考
							<a href="http://confluence.paas.sinopec.com/pages/viewpage.action?pageId=11343322#id-使用手册-_Toc4718118912" target="_blank">&lt;使用手册&gt;</a></small>
						</p>
					</div>
					<ol class="breadcrumb">
						<li><a href="#">项目管理</a></li>
						<li class="active">测试用例</li>
					</ol>
					<div id="page-content" class="form-horizontal">

						<div class="panel">
							<div class="panel-body pad-top-no">
								<div class="col-sm-3" style="border-right:1px solid #ccc;height:600px;">
										<div class="form-group row" style="margin-top: 20px;">
							            	<label class="col-xs-2 control-label" >分类:</label>
							            	<div class="col-xs-10" style="padding-right:0;">
												<select class=" form-control" id="type" style="width:90%!important;"onchange="testCase_left.typeChange();">
													<option value = 'area'>区域</option>
													<option value = 'iteration'>迭代</option>
													<option value = 'testplan'>测试计划</option>
													<option value = 'priority'>优先级</option>
													<option value = 'state'>状态</option>
												</select>
											</div>
							         	</div>

							         	<hr style="margin-bottom:11px;">
							         	<a class="tree_menu" type="button" id="showAll" title="显示全部子信息">
												<span class="icon child-node-icon"></span>
										</a>
										<a class="tree_menu" type="button" id="expandAllBtn" title="全部展开">
												<span class="icon icon-tree-expand-all"></span>
										</a>
										<a class="tree_menu" type="button" id="collapseAllBtn" title="全部折叠">
												<span class="icon icon-tree-collapse-all"></span>
										</a>
										<hr style="margin-top:10px;">
										<div class="zTreeDemoBackground left" style="height:450px;overflow:auto;">
											<ul id="treeDemo" class="ztree"></ul>
										</div>
								</div>
								<div class="col-sm-9" >
									<div class ="panel-title testCase_right_title">
										<h4>列表显示</h4>
										<a id="toExecl" class="btn btn-primary pull-right" >
											<span class="glyphicon glyphicon-export"></span>
											导出
										</a>
										<a id="fromExecl" class="btn btn-primary pull-right" style="margin-right:5px;">
										<span class="glyphicon glyphicon-open "></span>
											导入
										</a>
										<a class="btn btn-primary pull-right" id="sync" style="margin-right:5px;"><span class="glyphicon glyphicon-refresh"></span> 同步</a>
										<a class="btn btn-primary pull-right" id="insertCase"  style="margin-right:5px;">
											<i class="fa fa-plus"></i> 添加
										</a>
										<a class="btn btn-primary pull-right" id="" disabled="true" style="margin-right:5px;">
											关联需求
										</a>
									</div>

									<hr style="margin:0;">
									<div id="testCase_list">
										<div id="toolbar">
											<form id="search_form" class="form-inline" autocomplete="off">
												<label class="control-label width-auto" for="appGroup">模块:</label>
												<select class="form-control" id="moduleId" name="moduleId" onchange="testCase_list.moduleChange();"style="width: 15%!important;">
												</select>

												<label class="control-label width-auto" for="appGroup">指派人:</label>
												<select class="form-control" id="assigner" name="assigner" onchange="testCase_list.assignerChange();"style="width: 15%!important;">
												</select>

												<label class="control-label width-auto" for="appGroup">创建人:</label>
												<select class="form-control" id="author" name="author" onchange="testCase_list.authorChange();"style="width: 15%!important;">
												</select>

												<a id = "reset" class = "btn btn-gray" style="margin-top: 2px;width:50px;" onclick="testCase_list.resetTable();"> 重置</a>

<!-- 												<a class="btn btn-primary pull-right" id="insertCase"  style="margin-top: 2px;margin-left:10px;"> -->
<!-- 													<i class="fa fa-plus"></i> 添加 -->
<!-- 												</a> -->
<!-- 												<a class="btn btn-primary pull-right" id="" disabled="true" style="margin-top: 2px;margin-left:10px;"> -->
<!-- 													关联需求 -->
<!-- 												</a> -->
<!-- 												<a class="btn btn-primary pull-right" onclick="addApp()" style="margin-top: 2px;"> -->
<!-- 													列表 -->
<!-- 												</a> -->

											</form>
										</div>
	                                  <table id="testCaseTable" class="table" data-single-select="true" data-toolbar="#toolbar" 
	               						data-show-columns="true"
	               						 data-buttons-class="hover-primary">
	                                      <thead>
									        <tr>
									            <th data-field="" data-checkbox="true"></th>
									            <th data-field="name">用例名称</th>
									            <th data-field="state" data-formatter="stateFormatter">状态</th>
									            <th data-field="areaName" >区域</th>
									            <th data-field="priority" >优先级</th>
									            <th data-field="iterationName" >迭代</th>
									            <th data-field="moduleNm" >模块</th>
									            <th data-field="assignNm" >指派人</th>
									            <th data-field="authorNm" >创建人</th>
									            <th data-align="center" data-width="140" data-formatter="pref_btns">操作</th>
									        </tr>
									    </thead>
	                                  </table>
								</div>

								
								</div>

							</div>
						</div>

					</div>
		</div>
	</div>
<div id ="attachmentUploadHtml" style="display:none;">
		<form id ="attachmentUpload" class="form-horizontal" >
	         <div class="row" style="margin:30px 0 20px 0 ;padding-right:10px;">
		         <div class = "form-group col-sm-12 col-xs-12">
		            <label class="col-xs-2" style="padding:6px 0 0 0;text-align:right;"><font color=red>*</font>上传附件:</label>
		            <div class="col-xs-10  create_input" style="padding-right:0;">
		            	<input type="file" class="  form-control" id="file" name="file"   class="file"  onchange="fileChange(this);">
		         	</div>
		         </div>
	         </div>
	       </form>
		</div>

		<%--=========================  过程可视化消息栏  ==========================--%>
		<jsp:include page="../common/framework/aside.jsp" />

		<%--=========================  左侧菜单  ==========================--%>
		<jsp:include page="../common/framework/lefter.jsp" />

	</div>

	<%--=========================  页面底部版权信息  ==========================--%>
	<jsp:include page="../common/framework/footer.jsp" />
	<%--=========================  选择皮肤功能  ==========================--%>
	<jsp:include page="../common/framework/page-set.jsp" />
</div>
	<div id="floating-top-right" class="floating-container"></div>
<%--===================================================--%>
<%-- END OF CONTAINER --%>

<jsp:include page="../common/framework/script.jsp" />
	<script src="${pageContext.request.contextPath}/static/js/common/bootdatatable.init.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugin/bootstrap-table/bootstrap-table.min.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugin/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
	<script src="${pageContext.request.contextPath}/static/js/common/jquery.ztree.core.js"></script>
	<script src="${pageContext.request.contextPath}/static/js/common/jquery.contextMenu.js"></script>
	<script src="${pageContext.request.contextPath}/static/js/testCase/testCase.js"></script>

	<script type="text/javascript">
	var insertFlag = "testcase";
	/* =========================左侧树部分开始 =========================== */
	var textFlag = "list";
	var zNodes = [];
	var setting = {
			view: {
				showIcon: false,
				fontCss : {color:"#26a0f5"}
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
 				onClick: testCase_left.zTreeOnClick
			}
		};

// 	$(document).ready(function(){
// 		testCase_left.initZtree();
// 	});
	//显示全部子信息按钮触发
	$("#showAll").click(function(){
		if($("#showAll").hasClass("showAll_open")){
			$("#showAll").removeClass("showAll_open");
			showAll = false;
		}else{
			$("#showAll").addClass("showAll_open");
			showAll = true;
		}
		var params={
	            silent: true,
	            url:path+"/testCaseController/listTestCase?chooseType="+chooseType
				+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
	    };
		$('#testCaseTable').bootstrapTable('refresh',params);
		testCase_list.listQueryParams();
// 		$("#showAll").addClass("showAll_open");
		
	});
	/* =========================左侧树部分结束 =========================== */

	$(function(){
			testCase_left.typeChange();
			testCase_list.listQueryParams();

		});

		

		/* =========================列表部分开始 =========================== */
		var chooseType = "";
		var nodeId = "";
		var showAll = false;
		var moduleId = "";
		var assignId = "";
		var authorId = "";
		$(function() {
			//加载表格
			$('#testCaseTable').bootdatagrid(
					"${pageContext.request.contextPath}/testCaseController/listTestCase?chooseType="+chooseType
							+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId, {
						pagination : true,
						pageNumber : 1,
						pageSize : 5000,
						dataType:'json',
						singleSelect : false,
						striped : true,
						clickToSelect : true
			});

		});
		//操作列格式转换
		function pref_btns(value,row,index){
			var btns = '';
			btns += '<a class="btn-table-cell" onclick="addOrEditTestCase('+index+');">编辑</a>';
			btns += ' | <a class="btn-table-cell"onclick="testCase_list.deleteTestCase('+index+');">删除</a>';
			return btns;
		}
		//状态列格式转换
		function stateFormatter(value,row,index){
			var stateName = '';
			if(value == 1){
				stateName = "就绪";
			}else if(value == 2){
				stateName = "设计";
			}else if(value == 3){
				stateName = "已关闭";
			}
			return stateName;
		}

		 //导入execl
	    $("#fromExecl").click(function(){
	    	$('#file').val("");
	    	layer.open({
				type : 1,
				title : '导入测试用例',
				fix : true,
				scrollbar : false,
//		 		maxmin: true, //开启最大化最小化按钮
				area : [ '500px', '220px' ],
				shift : 2,
				content : $('#attachmentUploadHtml'),
				btn:['确定','取消'],
				success: function(layero, index){
					if(!$('.layui-layer-title').has('span').length){
						 $(".layui-layer-title").prepend("<span class='glyphicon glyphicon-th-large' ></span>&nbsp;");
					 }
			  	},
				end : function() {
				},
				yes: function(index, layero){
					if($('#file').val() != ""){
						$("#attachmentUpload").ajaxSubmit({
							type : "POST",
							url : path+"/testCaseController/importTestCase?chooseType="+chooseType
							+"&&nodeId="+nodeId,
							processData:false,
							dataType : 'json',
					        success : function(data) {
					        	moduleId = "";
								assignId = "";
								authorId = "";
					        	var params={
							            silent: true,
							            url:path+"/testCaseController/listTestCase?chooseType="+chooseType
										+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
							    };
								$('#testCaseTable').bootstrapTable('refresh',params);
								testCase_list.listQueryParams();
					        	layer.closeAll();
					        	toast.success('新增成功:'+data.insertSucCnt+', 新增失败:'+data.insertFailCnt+', 更新成功:'+data.updateSucCnt+', 更新失败数:'+data.updateFailCnt,'成功提示');
					        }
						});
					}else{
						toast.info ('请选择您需要上传的文件！','信息提示');
					}
					
				  },
				btn2: function(index, layero){
				    //按钮【按钮二】的回调
				  },
			});
	    });
	    
	    
	    //导出execl 
	    $("#toExecl").click(function(){
	    	window.location.href=path+"/testCaseController/exportTestCase?chooseType="+chooseType
			+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId;
	    });
	    
	    
	  //同步
	    $("#sync").click(function(){
	    	layer.open({
				type : 2,
				title : '同步数据',
				fix : true,
				scrollbar : false,
				area : [ '1000px', '600px' ],
				shift : 2,
				content : '${pageContext.request.contextPath}/testCaseController/syncData',
// 				btn: ['取消'],
// 					yes : function(index, layer) {
// 			            var iframeWin = layer.find('iframe')[0];
// 			            iframeWin.contentWindow.closeLayer();
// 			        },
// 			        btn2:function(index, layer) {
// 			        },
		        success: function(layero, index){
					if(!$('.layui-layer-title').has('span').length){
						 $(".layui-layer-title").prepend("<span class='glyphicon glyphicon-th-large' ></span>&nbsp;");
					 }
			  	},
				end : function(){
// 					if(loadFlag == 1){
// 						var params={
// 	    			            silent: true,
// 	    			            url:path+"/testCaseController/listTestCase?chooseType="+chooseType
// 	    						+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
// 	    			    };
// 	    				$('#testCaseTable').bootstrapTable('refresh',params);
// 					}
				}
			});
	    });
	    
	    
	    //文件类型和大小的控制
	    var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
	    function fileChange(target,id) {
	        var fileSize = 0;
	        var filetypes =[".xls",".xlsx"];
	        var filepath = target.value;
	        var filemaxsize = 1024*2;//2M
	        if(filepath){
	            var isnext = false;
	            var fileend = filepath.substring(filepath.lastIndexOf("."));
	            if(filetypes && filetypes.length>0){
	                for(var i =0; i<filetypes.length;i++){
	                    if(filetypes[i]==fileend){
	                        isnext = true;
	                        break;
	                    }
	                }
	            }
	            if(!isnext){
// 	                alert("不接受此文件类型！");
	                toast.info ('只接受".xls",".xlsx"类型的文件！','信息提示'); 
	                target.value ="";
	                return false;
	            }
	        }else{
	            return false;
	        }
	        if (isIE && !target.files) {
	            var filePath = target.value;
	            var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
	            if(!fileSystem.FileExists(filePath)){
	                toast.info ('附件不存在，请重新输入！','信息提示'); 
	                return false;
	            }
	            var file = fileSystem.GetFile (filePath);
	            fileSize = file.Size;
	        } else {
	            fileSize = target.files[0].size;
	        }

	        var size = fileSize / 1024;
	        if(size>filemaxsize){
	            toast.info ('附件大小不能大于'+filemaxsize/1024+'M！','信息提示'); 
	            target.value ="";
	            return false;
	        }
	        if(size<=0){
	            toast.info ('附件大小不能为0M！','信息提示'); 
	            target.value ="";
	            return false;
	        }
	    }
	    
	    
	    
		/* =========================列表部分结束 =========================== */

		/* =========================新建编辑测试用例部分开始 =========================== */

		//添加按钮
		$("#insertCase").click(function(){
			var index = -1;

			addOrEditTestCase(index);
		});
		var flag;
		var loadFlag = 0;
		//添加或编辑模块
		function addOrEditTestCase(index){
			setTimeout(function() {
				$(".fixed-table-container tbody tr[data-index='"+index+"']").addClass("selected");
			}, 50);
			flag = index;
			//没有登录信息//用户为普通用户则无法编辑
				layer.open({
					type : 2,
					title : (index != -1) ? '编辑用例' : '添加用例',
					fix : true,
					scrollbar : false,
					area : [ '1000px', '600px' ],
					shift : 2,
					content : '${pageContext.request.contextPath}/testCaseController/addOrEditTestCase',
					btn: ['确定', '取消'],
						yes : function(index, layer) {
				            var iframeWin = layer.find('iframe')[0];
				            iframeWin.contentWindow.submit();
				        },
				        btn2:function(index, layer) {
				        },
			        success: function(layero, index){
						if(!$('.layui-layer-title').has('span').length){
							 $(".layui-layer-title").prepend("<span class='glyphicon glyphicon-th-large' ></span>&nbsp;");
						 }
				  	},
					end : function(){
						if(loadFlag == 1){
							var params={
		    			            silent: true,
		    			            url:path+"/testCaseController/listTestCase?chooseType="+chooseType
		    						+"&&nodeId="+nodeId+"&&showAll="+showAll+"&&moduleId="+moduleId+"&&assignId="+assignId+"&&authorId="+authorId
		    			    };
		    				$('#testCaseTable').bootstrapTable('refresh',params);
						}
					}
				});

		};


</script>
</body>
</html>

